$(document).ready(function(){
    siteTime() ;
    randomCard() 
    $(".to-cate").click(function () {
        $(".site-title").toggleClass("turnTo-180deg") ;
        $(".category-page").toggleClass("turnTo-0deg") ;
    }) ;
    $(".fun-btn-1").click(function () {
        window.location.reload() ; 
    }) ;
    $(function() {
        var x = 10;
        var y = 20;
        $("a").mouseover(function(e) {
            this.myTitle = this.title;
            if (this.myTitle||this.myTitle=="javascript:;") {
               var tooltip = "<div id='tooltip'>" + this.myTitle + "</div>"; //创建DIV元素
            } else {
               var tooltip = "<div id='tooltip'>" + "UNKNOWN" + "</div>"; //创建DIV元素
            }
            this.title = "";
            
            var newLink = "<div id=\"link\"></div>" ;
            $("#link").append(tooltip); //追加到文档中
            $("#tooltip").css({
                "top": (e.pageY + y) + "px",
                "left": (e.pageX + x) + "px"
            }).show(); //设置X  Y坐标， 并且显示
        }).mouseout(function() {
            this.title = this.myTitle;
            $("#tooltip").remove(); //移除
        }).mousemove(function(e) {
            $("#tooltip").css({
                "top": (e.pageY + y) + "px",
                "left": (e.pageX + x) + "px"
            });
        })
    }) ;
}) ;

function siteTime(){
    window.setTimeout("siteTime()", 1000);
    var seconds = 1000 ;
    var minutes = seconds * 60;
    var hours = minutes * 60;
    var days = hours * 24;
    var years = days * 365;
    var today = new Date();
    var todayYear = today.getFullYear();
    var todayMonth = today.getMonth();
    var todayDate = today.getDate();
    var todayHour = today.getHours();
    var todayMinute = today.getMinutes();
    var todaySecond = today.getSeconds();
    /* Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳) 
    year - 作为date对象的年份，为4位年份值
    month - 0-11之间的整数，做为date对象的月份
    day - 1-31之间的整数，做为date对象的天数
    hours - 0(午夜24点)-23之间的整数，做为date对象的小时数
    minutes - 0-59之间的整数，做为date对象的分钟数
    seconds - 0-59之间的整数，做为date对象的秒数
    microseconds - 0-999之间的整数，做为date对象的毫秒数 */
    var t1 = Date.UTC(2019,7,15,00,00,00);
    var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
    var diff = t2-t1;
    var diffYears = Math.floor(diff/years);
    var diffDays = Math.floor((diff/days)-diffYears*365);
    var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
    var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
    var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            /* document.getElementById("sitetime").innerHTML=" 已运行"+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒" */
    document.getElementById("site-time").innerHTML="Catch fish:"+(diffYears*365+diffDays)+"days-"+diffHours+"h-"+diffMinutes+"m-"+diffSeconds+"s" ;
};

function getHitokoto(){
    
  fetch('https://v1.hitokoto.cn')
    .then(response => response.json())
    .then(data => {
      const hitokoto = document.getElementById('hitokoto-text') ;
      const info = document.getElementById('hitokoto-info') ;
      hitokoto.href = 'https://hitokoto.cn/?uuid=' + data.uuid ;
      hitokoto.innerText = data.hitokoto ;
      if (null==data.from_who) {
        data.from_who="UNKNOWN" ;
      } else {}
      info.innerText = data.from+"-"+data.from_who ;
    })
    .catch(console.error) ;

} ;

function randomCard() {
    var classLen=3 ;
     
    $(".card").each(function(){
        // let this = $(this);
        var newCard = "card"+Math.ceil(Math.random()*classLen); 
        console.log($(this).addClass(newCard));
    });  
}